home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac-Source 1994 July
/
Mac-Source_July_1994.iso
/
C and C++
/
Libraries
/
TurboTCP 1.0.1
/
TurboTCP.source
/
CTCPStream.h
< prev
next >
Wrap
Text File
|
1993-12-10
|
10KB
|
290 lines
/*
** CTCPStream.h
**
** TurboTCP support library
** TCP stream class
**
** Copyright © 1993, FrostByte Design / Eric Scouten
**
*/
#pragma once
#ifndef TurboTCPHeaders
#include <CCollaborator.h>
#include <CCluster.h>
#include <MacTCPCommonTypes.h>
#include <TCPPB.h>
#include "TurboTCP.const.h"
#endif
CLASS CTCPAsyncCall;
// reason codes for TCP stream notifications
enum {
tcpStreamClosed = 1, // connection closed info = NULL
tcpStreamClosing, // connection is closing info = TRUE if remote host cause close
tcpStreamDataArrived, // data arrived info = (DataArrivedInfo *)
tcpStreamDataSent, // data was sent info = (wdsEntry *)
tcpStreamICMP, // ICMP notification info = (struct ICMPReport *)
tcpStreamOpened, // connection opened info = NULL
tcpStreamOpenFailed, // couldn’t open session info = (OSErr) the result code
tcpStreamSendFailed, // couldn’t send data info = (SendFailedInfo *)
tcpStreamTCPError, // TCP error occurred info = (TCPErrorInfo *)
tcpStreamTerminated, // session terminated info = (TerminatedInfo *)
tcpStreamTimeout, // timeout occurred info = NULL
tcpStreamUnexpectedData, // unexpected data arrived info = NULL
tcpStreamUrgentBegin, // urgent data begins info = NULL
tcpStreamLastChange = tcpStreamUrgentBegin
};
// type definitions for TCP stream notifications to dependent objects
typedef struct DataArrivedInfo {
Ptr theData;
b_16 theDataSize;
Boolean isUrgent;
} DataArrivedInfo;
typedef struct SendFailedInfo {
wdsEntry *WDSPtr;
OSErr theResultCode;
} SendFailedInfo;
typedef struct TCPErrorInfo {
OSErr theResultCode;
short theCsCode; // the MacTCP operation which failed
} TCPErrorInfo;
typedef struct TerminatedInfo {
b_16 terminReason;
Boolean aboutToDispose; // TRUE if stream will be disposed
} TerminatedInfo;
// connection state codes for TCP Status call
enum {
strClosed = 0,
strListen = 2,
strSYNReceived = 4,
strSYNSent = 6,
strEstablished = 8,
strFINWait1 = 10,
strFINWait2 = 12,
strCloseWait = 14,
strClosing = 16,
strLastAck = 18,
strTimeWait = 20
};
// miscellaneous constants
#define autoReceiveMax 32 // maximum # of entries in RDS
#define IPOptionStringSize 40
typedef char IPOptionString [IPOptionStringSize];
/*______________________________________________________________________
**
** CTCPStream
**
** This class implements a stream for MacTCP. A TCP stream supports one connection at
** a time; but a connection may be closed and another connection opened without releasing
** the stream.
**
** IMPORTANT: This object is a descendant of CCollaborator. Your application class should
** make itself a dependent of this object so that it may receive notification of resolver
** call completions.
**
** All MacTCP commands are originated through this class. (See the methods labelled
** “basic user TCP calls” below.) These methods originate asynchronous calls to the
** MacTCP driver by creating CTCPAsyncCall objects to correspond with each call. When
** the call is completed, notification is passed back to the caller by means of the
** BroadcastChange mechanism.
**
** This object also receives notification of asynchronous events related to the stream and
** passes these notifications to its dependents through the BroadcastChange mechanism.
** (See the description of the asynchronous notification routine [ASR] in the MacTCP
** manuals.)
**
** Your application class need not be concerned with interrupt-level constraints on
** memory management. The CTCPStream object queues notifications received at interrupt
** level and the CTCPDriver schedules their processing at the next event loop.
**
*/
class CTCPStream : public CCollaborator {
public:
ip_addr itsRemoteIP; // remote host’s IP address
b_16 itsRemotePort; // remote host’s TCP port
ip_addr itsLocalIP; // local host’s IP address
b_16 itsLocalPort; // local host’s TCP port
Boolean rcvUrgent; // stream is receiving urgent data
Boolean hasSessionOpen; // currently open session
protected:
Ptr macTCPStream; // MacTCP’s reference code for this stream
Handle itsBuffer; // receive buffer area
long itsBufferSize; // size of receive buffer
b_16 sendNextUrgent; // next send operation is “urgent” data
Boolean sendNextPush; // next send operation is “push” data
Boolean notifClosing; // ASR got closing event
Boolean remoteClose; // ASR close due to remote host
Boolean notifTimeout; // ASR got ULP timeout event
Boolean notifTerminate; // ASR got terminate event
b_16 notifTermReason; // ASR’s termination reason
Boolean notifDataArrived; // ASR got data w/ no receive
Boolean notifUrgent; // ASR got urgent data event
Boolean notifICMP; // ASR got ICMP report
ICMPReport notifICMPreport; // most recent ICMP report
CCluster *itsAsyncCalls; // list of outstanding async calls
RcvBypassProc itsRcvBypassProc; // receive bypass procedure
CObject *itsRcvBypassTarget; // who to call from ^^^
byte itsULPtimeout; // ULP timeout value in seconds
byte itsULPaction; // what to do on ULP timeout
byte itsValidityFlag; // validity bits for optional parms
byte itsCommandTimeoutValue; // command timeout value in seconds
byte itsTosFlags; // type of service flags
byte itsPrecedence; // precedence level
byte itsDontFrag; // don’t fragment flag
byte itsTimeToLive; // time to live
byte itsSecurity; // security flag
byte itsOptionCnt; // count of options bytes
byte itsOptions[IPOptionStringSize]; // IP options
Boolean pendingOpen; // session is being opened
Boolean pendingClose; // session is being closed
Boolean pendingAbort; // session is being aborted
Boolean pendingNotify; // stream is in ProcessNotify queue
Boolean pendingDispose; // stream is in ProcessDispose queue
Boolean disposeOnTerminate; // dispose stream when terminate notification comes
Boolean receivedClose; // received notification that session was closed or aborted
Boolean receivedTerminate; // terminate notification has been received
short itsAutoReceiveSize; // auto-receive size (# of entries)
short itsAutoReceiveNum; // number of simultaneous receive calls to issue
TurboTCPQElem qNotifyEntry; // notification queue entry
TurboTCPQElem qDisposeEntry; // disposal queue entry
// initialize/destroy stream
public:
void ITCPStream (long recBufferSize, short autoReceiveSize, short autoReceiveNum);
virtual void Dispose (void);
virtual void OwnerDied (void);
// basic user TCP calls
void OpenConnection (Boolean passive, ip_addr theRemoteIP, b_16 theRemotePort,
b_16 theLocalPort);
void Close (void);
void Abort (void);
void NoCopyRcv (rdsEntry *itsRDS, b_16 itsRDSSize, b_16 itsTimeOut);
void BfrReturn (Ptr itsRDS);
void Send (wdsEntry *itsWDS, b_16 itsTimeOut, Boolean disposeWDS);
void Receive (Ptr theData, b_16 itsDataSize, b_16 itsTimeOut);
void Status (TCPStatusPB *theStatusBlock);
b_16 ConnectionState (void);
// specialized functions for sending data
void SendChar (char theChar);
void SendCString (char *theString);
void SendPString (ConstStr255Param theString);
void SendBfrCpy (Ptr theData, b_16 theDataSize);
void SendBfrNoCpy (Ptr theData, b_16 theDataSize, Boolean disposeWhenDone);
void SetNextPush (void);
void SetNextUrgent (Boolean useRFC793);
// notification routines
virtual void HandleTCPError (OSErr theResultCode, short theCsCode);
virtual void HandleClosed (void);
virtual void HandleClosing (Boolean remoteClosing);
virtual void HandleDataArrived (Ptr theData, b_16 theDataSize,
Boolean isUrgent);
virtual void HandleDataSent (wdsEntry *WDSPtr);
virtual void HandleICMP (struct ICMPReport *icmpMsg);
virtual void HandleOpened (void);
virtual void HandleOpenFailed (OSErr theResultCode);
virtual void HandleSendFailed (wdsEntry *WDSPtr, OSErr theResultCode);
virtual void HandleTerminated (b_16 terminReason);
virtual void HandleTimeout (void);
virtual void HandleUnexpectedData (void);
virtual void HandleUrgentBegin (void);
// set configuration
void InstallRcvBypass (CObject *whoToCall, RcvBypassProc aRcvBypassProc);
private: static void GiveBypassToAsyncCall (CObject *theObject, long param); public:
void SetULPTimeoutValue (b_16 ulpTimeoutValue);
void SetULPTimeoutAction (b_16 ulpTimeoutAction);
void SetCommandTimeout (b_16 cmdTimeoutValue);
void SetTypeOfService (b_16 newTosFlag);
void SetPrecedence (b_16 newPrecedence);
void SetDontFrag (b_16 newDontFrag);
void SetTimeToLive (b_16 newTimeToLive);
void SetSecurity (b_16 newSecurity);
void SetIPOptions (b_16 newOptionsSize, IPOptionString *newOptions);
// TCP urgent mode
Boolean RcvUrgentStatus (void);
void RcvUrgentBegin (void);
void RcvUrgentMark (void);
// protected methods to issue TCP calls
protected:
OSErr DoAsyncCall (b_16 theCsCode, TCPiopb *theParamBlock);
OSErr DoSyncCall (b_16 theCsCode, TCPiopb *theParamBlock);
// auto-receive processing
void IssueAutoReceive (void);
// modified collaborator mechanism
void BroadcastSafeChange (long reason, void *info);
// delayed-processing routines: respond to interrupt notifications
public:
void ProcessNotify (void);
void ProcessAsyncCompletion (CTCPAsyncCall *theCall);
// interrupt-level methods: delay processing for non-interrupt status
void PostponeDispose (void);
protected:
void PostponeNotify (b_16 eventCode, b_16 terminReason, struct ICMPReport *icmpMsg);
static pascal void NotifyProc (StreamPtr tcpStream, unsigned short eventCode,
Ptr userDataPtr, unsigned short terminReason,
struct ICMPReport *icmpMsg);
};